<template>
	<div class="confirm-modal-box medical-waste">
        <div class="condition-filter-box classify-sort">
            <button :class="['button',todayActive ? 'btn-active' : '']" @click="handleCheckToday">今日</button>
            <el-date-picker
                v-model="day"
                type="date"
                :clearable="false"
                placeholder="选择日期"
                @change="handleChangeDay"
                :picker-options="pickerOptions"
            />
            <el-time-picker
                is-range
                v-model="time"
                format="HH:mm"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                placeholder="选择时间范围"
                @change="handleChangeTime"
            />
            <el-popover
                placement="bottom"
                width="400"
                trigger="hover">
                <div class="time-icon-list">
                    <span v-for="(timei,key) in timeType" :key="key" :class="['icon',timei.curr?`icon${key+7}` : `icon${key+1}`]" @click="handleSetTime(timei,key)"></span>
                </div>
                <el-button slot="reference">快捷选择</el-button>
            </el-popover>
            <button :class="['button',canHideEmptyType ? 'btn-active' : '']" @click="switchEmptyType">不显示未产生类型</button>
            <ExportBtn v-if="exportLimit != '1' && tableData.length > 0" :name="'导出'" :currOrders="currOrders" :fileName="`医废数据 ${exportDay}`" />
            <el-button v-else class="primary-btn" type="primary" @click="showTips" :disabled="isExporting">导出</el-button>

            <div class="date-picker-btn" @click="switchCalendar">
                <el-badge class="item"  :value="wasteNum" :max="99">
                    <span class="calendar-icon"></span>
                </el-badge>
            </div>
        </div>

        <template v-if="canShowCalendar">
            <Calendar :date="startTime" :option="option" :sign="after" @change="changeDayFn"></Calendar>
        </template>
        <div v-if="canShowCalendar" class="kj-confirm-mask calendar-mask" @click="switchCalendar"></div>

        <p class="date-tips" v-if="showDate.time != ''">当前搜索结果为 {{showDate.time}} 的数据，<span @click="goSearchToday">点击返回全天</span></p>

        <div class="el-table el-table--border " v-if="tableData.length > 0">
            <table v-for="(tbodyi,index) in tableData" :key="index" :class="[index != 0 && tableData[index-1].title != tbodyi.title ? 'border-tr' : '']">
                <thead class="title">
                    <tr :class="[index != 0 && tableData[index-1].title == tbodyi.title ? 'hide-tr' : '']">
                        <td width="317"></td>
                        <td width="195"></td>
                        <td width="147">
                            <div class="text" v-if="index == 0 || tableData[index-1].title != tbodyi.title">{{tbodyi.name}}</div>
                        </td>
                        <td width="206"></td>
                        <td width="196"></td>
                        <td></td>
                    </tr>
                </thead>
                <colgroup>
                    <col v-for="(cloi,cind) in colL" :key="cind">
                </colgroup>
                <thead class="is-group">
                <tr v-if="index == 0 || tableData[index-1].title != tbodyi.title">
                    <th v-for="(thi,thind) in colL" :key="thind" class="is-center">
                        <div class="cell">{{thi.title}}<i v-if="thind == 0 && showDate.time == ''" class="el-icon-setting set-icon" @click="switchTimeModal(true)"></i></div>
                    </th>
                </tr>
                </thead>
                
                <tbody>
                    <tr v-if="tbodyi.typeL.length == 0">
                        <td class="is-center"><div class="cell">
                            {{showDate.day}}
                            <div v-if="tbodyi.time != ''" class="tbody-time">{{tbodyi.time}}</div>
                            <div v-else class="tbody-time">{{showDate.time}}</div>
                        </div></td>
                        <td class="is-center"><div class="cell">暂无数据</div></td>
                        <td class="is-center"><div class="cell">暂无数据</div></td>
                        <td class="is-center"><div class="cell">暂无数据</div></td>
                        <td class="is-center"><div class="cell">暂无数据</div></td>
                        <td class="is-center"><div class="cell">{{tbodyi.title}}</div></td>
                    </tr>
                    <tr v-else v-for="(tri,trind) in tbodyi.typeL" :key="trind">
                        <td class="is-center" v-if="trind==0" :rowspan="tbodyi.typeL.length"><div class="cell">
                            {{showDate.day}}
                            <div v-if="tbodyi.time != ''" class="tbody-time">{{tbodyi.time}}</div>
                            <div v-else class="tbody-time">{{showDate.time}}</div>
                        </div></td>
                        <td class="is-center pointer" :style="{'background-color':tri.color,color:'#333'}" @click="handleShowClassifyOrder(tri)"><div class="cell">{{tri.title}}</div></td>
                        <td class="is-center"><div :class="['cell', tri.num == 0 ? 'empty-tips' : '']">{{tri.num == 0 ? '暂无数据' : tri.num}}</div></td>
                        <td class="is-center"><div :class="['cell', tri.weight == 0 ? 'empty-tips' : '']">{{tri.weight == 0 ? '暂无数据' : `${tri.weight.toFixed(2)}kg`}}</div></td>
                        <td class="is-center" v-if="trind==0" :rowspan="tbodyi.typeL.length"><div class="cell">
                            {{tbodyi.staff.join('，')}}
                        </div></td>
                        <td :class="['is-center',tbodyi.title=='点击交接' ? (tbodyi.staff.length != 0 ? 'enable-btn' : 'disable-btn'): '', , tbodyi.title == '暂无数据'? 'no-data' : '']" v-if="trind==0" :rowspan="tbodyi.typeL.length"><div class="cell" style="width:95px;margin: auto;" @click="handleShowConfirm(tbodyi)">
                            {{tbodyi.title}}
                        </div></td>
                    </tr>
                </tbody>
            </table>
        </div>

        <div v-else class="no-txt">暂无数据</div>

        <el-dialog
            title="自定义时间"
            :visible.sync="canShowTimeModal"
            :modal-append-to-body="false"
            width="400px">
                <div>
                    <el-time-picker
                        size="mini"
                        is-range
                        v-model="customForm.time1"
                        format="HH:mm"
                        range-separator="-"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间"
                        placeholder="选择时间范围"
                        @change="saveTime">
                    </el-time-picker>
                    <br/><br/>
                    <el-time-picker
                        size="mini"
                        is-range
                        v-model="customForm.time2"
                        format="HH:mm"
                        range-separator="-"
                        start-placeholder="开始时间"
                        end-placeholder="结束时间"
                        placeholder="选择时间范围"
                        @change="saveTime">
                    </el-time-picker>
                    <!-- selectableRange的时间范围应该是第一个时间的其余时间段，如：['09:30:00 - 12:00:00', '14:30:00 - 18:30:00'] -->
                    <button class="sure-btn" @click="postTimeData">确定</button>
                </div>
        </el-dialog>

        <el-dialog
            :title="orderLis.title"
            :visible.sync="orderShow"
            :modal-append-to-body="false"
            width="90%">
            <WasteLis
                :order="orderLis"
            ></WasteLis>
        </el-dialog>

        <el-dialog
            title="医废确认"
            :visible.sync="confirmShow"
            :modal-append-to-body="false"
            width="740px">
            <HandConfirm
                v-if="confirmShow"
                :order="confirmOrder"
                :show-time="showDate"
                @sure="handleSureSuccess"
                @show-order="handleShowClassifyOrder"
            ></HandConfirm>
        </el-dialog>

        <div class="v-mask" v-if="canShowTips" @click="hideTips"></div>
        <ExportWarmTips 
          v-if="canShowTips"
          :data="undoTableData" 
          :day="exportDay"
          @handle-jump="switchDayLis"
          @handle-close="hideTips">
          <div class="export-btn">
            <ExportBtn 
              :name="'立即导出'"
              :curr-orders="currOrders" 
              :file-name="`医废数据 ${exportDay}`" 
              @handleCancel="hideTips"
            />
          </div>
        </ExportWarmTips>

        <BatchHandover 
          :show="canShowDayLis"
          :data="undoTableData"
          :col="colL"
          :day-lis="dayLis"
          :date="showDate"
          :export-day="exportDay"
          @handle-show-lis="switchDayLis"
          @handle-show-sign="switchSignModal"
          @handle-show-confirm="handleShowConfirm"
          @handle-show-classify-order="handleShowClassifyOrder"
        ></BatchHandover>

        <SignModal
          v-if="signVisible"
          :signType="'multiple'"
          :orders="undoTableData"
          @sure="handleSureSuccess"
          @handleCancel="switchSignModal"
        />
	</div>
</template>

<script>
  //这里的是交接1的 只能进行交接1的确定
  import today from '../../common/today'
  import WasteLis from './sub/WasteLis.vue'
  import HandConfirm from './sub/HandConfirm.vue'
  import Calendar from '../../tips/calendar.vue'
  import {
      getWasteCategoryUrl, diytimeUrl, wasteNumberUrl,
      getHconfLisUrl
  } from '../../common/ajax';
  import ExportBtn from './export-btn';
  import SignModal from '../../components/waste/sign-modal.vue'
  import ExportWarmTips from './export-warm-tips.vue'
  import BatchHandover from './batch-handover.vue'
	export default {
		data(){
			return {
        todayActive: true,
        day:new Date(),
        pickerOptions: {   // 禁选当天之后的日期
            disabledDate(date) {
                return date.getTime() > Date.now();
            }
        },
        timeType:[
            {title:'全天',time:{s:'00:00:00',e:'23:59:59'},curr:false},
            {title:'下午',time:{s:'13:00:00',e:'18:30:00'},curr:false},
            {title:'上午',time:{s:'07:00:00',e:'12:59:59'},curr:false},
            {title:'早上',time:{s:'06:00:00',e:'09:00:00'},curr:false},
            {title:'中午',time:{s:'11:00:00',e:'14:00:00'},curr:false},
            {title:'下午2',time:{s:'15:00:00',e:'19:00:00'},curr:false}
        ],
        time:'',
        colL:[
            {title:'时间',width:''},
            {title:'类型',width:''},
            {title:'数量',width:''},
            {title:'重量',width:''},
            {title:'收运称重人',width:''},
            {title:'状态',width:''}
        ],
        showDate:{day:'',time:''},
        tableData:[],
        orderLis:{},
        orderShow:false,
        confirmOrder:{},
        confirmShow:false,
        isHandle:true,
        canHideEmptyType: false,
        customForm:{
            time1: [
                new Date(`${today.otherTime(new Date())} 00:00:00`),
                new Date(`${today.otherTime(new Date())} 12:59:59`),
            ],
            time2: [
                new Date(`${today.otherTime(new Date())} 13:00:00`),
                new Date(`${today.otherTime(new Date())} 23:59:59`),
            ],
        },
        time2: '',
        canShowTimeModal: false,
        canShowCalendar: false,
        startTime: {
            time: today.init('YY-MM-DD')
        },
        option: {
            type: 'day',
            week: ['一', '二', '三', '四', '五', '六', '日'],
            month: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
            format: 'YYYY-MM-DD',
            placeholder: 'when?',
            inputStyle: {
                'display': 'inline-block',
                'padding': '6px',
                'line-height': '22px',
                'font-size': '16px',
                'border': '2px solid #fff',
                'box-shadow': '0 1px 3px 0 rgba(0, 0, 0, 0.2)',
                'border-radius': '2px',
                'color': '#5F5F5F'
            },
            color: {
                header: '#66bea7',
                headerText: '#fff'
            },
            buttons: {
                ok: '确定',
                cancel: 'Cancel'
            },
            overlayOpacity: 0.5, // 0.5 as default
            dismissible: true // as true as default
        },
        after:[
            // {year:'',month:'',day:'',sign:false},
        ],
        todayTime:today.init('YY-MM-DD'),
        wasteOrderData: [],
        wasteNum: 0,
        currOrders: [],  // 待导出数组
        exportDay: '',
        canShowTips: false,
        canShowDayLis: false,
        dayLis: {
            data: [],
            types: [
                // { namewc: '感染性', totals: '100' }
            ]
        },
        undoTableData: [],
        signVisible: false,
        isExporting: false,
        exportLimit: '',
        disabled: false
      }
    },
    watch: {
        day: function(){
            this.exportDay = today.otherTime(this.day)
        }
    },
    created(){
        this.isIE();
        this.checkExportLimit();
        this.checkStorage()
    },
    mounted(){
        this.isIE();
        this.handleSetTime(this.timeType[0],0);
        // this.handleGetLis(0)
        this.checkExportLimit();
        this.checkStorage()
    },
    methods:{
        isIE() {
            if(!!window.ActiveXObject || "ActiveXObject" in window){
                this.customForm.time1 = [
                    new Date(`${`${today.otherTime(new Date())}`.replace('-','/')} 00:00:00`),
                    new Date(`${`${today.otherTime(new Date())}`.replace('-','/')} 12:59:59`),
                ]
                this.customForm.time2 = [
                    new Date(`${`${today.otherTime(new Date())}`.replace('-','/')} 13:00:00`),
                    new Date(`${`${today.otherTime(new Date())}`.replace('-','/')} 23:59:59`),
                ]
            }
        },
        checkExportLimit(){
            jQuery.ajax({
                url: getHconfLisUrl,
                type: 'GET',
                success: function(data){
                    if(data.success){
                        this.exportLimit = data.data.hw_export_limit
                    }
                }.bind(this),
                error: function(err){
                    throwErrorTips('暂无数据',err.msg)
                }
            })
        },
        switchSignModal(){
            this.signVisible = !this.signVisible;
        },
        switchDayLis(){
            this.hideTips();
            this.canShowDayLis = !this.canShowDayLis
        },
        hideTips(isExporting){
            if(typeof(isExporting) == 'boolean') this.isExporting = isExporting;
            this.canShowTips = false;
        },
        showTips(){    //
            if(this.tableData.length == 0) {
                throwErrorTips('暂无数据','')
                return;
            }
            this.canShowTips = true;
        },
        getWasteNumber(){
            if(this.disabled) return;
            jQuery.ajax({
                url: wasteNumberUrl,
                type: 'get',
                success: function(data){
                    if(data.success){
                        this.wasteNum = data.data.total
                        this.wasteOrderData = data.data.days.filter(v => (v.split('-')[0] == '2019' && v.split('-')[1] > '08') || v.split('-')[0] > '2019')
                        this.wasteOrderData.forEach((v,i) => {
                            this.after.push({
                                year: today.getYearDay('YY',v),
                                month: today.getYearDay('MM',v),
                                day: today.getYearDay('DD',v),
                                sign: true
                            })
                        })
                    }
                }.bind(this)
            })
        },
        changeDayFn(){
            this.canShowCalendar = false;
            this.day = new Date(this.startTime.time);
            this.handleChangeDay();
        },
        switchCalendar(){
            this.canShowCalendar = !this.canShowCalendar;
            if(this.canShowCalendar ) this.getWasteNumber();//&& this.wasteOrderData.length == 0
        },
        switchTimeModal(boolean){
            this.canShowTimeModal = boolean;
        },
        saveTime(){
            if(this.customForm.time1 == null){
                this.customForm.time1 = [
                    new Date(`${today.otherTime(this.day)} 00:00:00`),
                    new Date(`${today.otherTime(this.day)} 12:59:59`),
                ]
                this.customForm.time2 = [
                    new Date(`${today.otherTime(this.day)} 13:00:00`),
                    new Date(`${today.otherTime(this.day)} 23:59:59`),
                ]
            }else if(this.customForm.time2 == null){
                let tmp = new Date(this.customForm.time1[1]).getTime() + 1000;
                this.customForm.time2 = [
                    new Date(tmp),
                    new Date(`${today.otherTime(this.day)} 23:59:59`),
                ]
            }
        },
        checkForm(){
            let st1 = this.customForm.time1[0];
            let et1 = this.customForm.time1[1];
            let st2 = this.customForm.time2[0];
            let et2 = this.customForm.time2[1];
            if(today.otherTime(new Date(st2),'hh:mm') > today.otherTime(new Date(et1),'hh:mm')){
                return true;
            }
            if(today.otherTime(new Date(et2),'hh:mm') < today.otherTime(new Date(st1),'hh:mm')){
                return true;
            }
            if(today.otherTime(new Date(st2),'hh:mm') > today.otherTime(new Date(st1),'hh:mm') && today.otherTime(new Date(st2),'hh:mm') < today.otherTime(new Date(et1),'hh:mm')){
                return false;
            }
            if(today.otherTime(new Date(et2),'hh:mm') > today.otherTime(new Date(st1),'hh:mm') && today.otherTime(new Date(et2),'hh:mm') < today.otherTime(new Date(et1),'hh:mm')){
                return false;
            }
        },
        postTimeData(){
            if(!this.customForm.time1 || !this.customForm.time2){
                alert('提交失败！两个时间段都不能为空');
                return;
            }
            if(!this.checkForm()){
                alert('提交失败！两个时间段不能重合');
                return;
            }
            var form = []
            for(let i = 0; i < 2; i++){
                form.push({
                    st: `${today.otherTime(new Date(this.customForm[`time${i+1}`][0]),'hh:mm')}`,
                    et: `${today.otherTime(new Date(this.customForm[`time${i+1}`][1]),'hh:mm')}`
                })
            }
            jQuery.ajax({
                url:  diytimeUrl,
                type: 'POST',
                data: JSON.stringify(form),
                success: function(res){
                    if(res.success){
                        this.switchTimeModal(false)
                        this.handleGetLis(0)
                    }
                }.bind(this)
            })
        },
        checkStorage(){ // 本地保存“不显示未产生类型”的选择状态
            let curr = JSON.parse(localStorage.getItem('hide_empty_type'))
            if(curr != null && typeof(curr) == "boolean"){
                this.canHideEmptyType = JSON.parse(localStorage.getItem('hide_empty_type'))
            }else{
                localStorage.setItem('hide_empty_type', JSON.stringify(this.canHideEmptyType))
            }
        },
        switchEmptyType(){
            localStorage.setItem('hide_empty_type', JSON.stringify(!this.canHideEmptyType))
            this.canHideEmptyType = !this.canHideEmptyType
            this.goSearchToday()
        },
        goSearchToday(){
            this.handleSetTime(this.timeType[0],0);
        },
        //日期
        handleCheckToday(){ //今日
            this.day = new Date()
            this.todayActive = true
            this.handleGetLis(0)
        },
        handleChangeDay(){  //日历设置日期
            setTimeout(()=>{
                if(this.day){
                    if(today.otherTime(this.day,'YY-MM-DD') != today.otherTime(new Date(),'YY-MM-DD')){
                        this.todayActive = false
                    }else {
                        this.todayActive = true
                    }
                    this.handleGetLis()
                }else {
                    this.handleCheckToday()
                }
            },20)
        },
        //时间
        handleSetTime(val,key){ //系统预定的
            this.timeType.forEach(function(item,ind){
                if(key != ind && key != 0){
                    item.curr = false
                }
            });
            let d = new Date()
            d.setHours(0)
            d.setMinutes(0)
            d.setSeconds(0)
            d.setMilliseconds(0)
            let timestamp = d.getTime()
            if(val.curr && key == 0){
                this.time = [
                    timestamp,
                    timestamp + (23*3600+59*60+59)*1000
                ]
            }else {
                let s=val.time.s.split(':'),e=val.time.e.split(':');
                this.time = [
                    timestamp + (Number(s[0]) * 3600 + Number(s[1])*60  + Number(s[2]))*1000,
                    timestamp + (Number(e[0]) * 3600 + Number(e[1])*60  + Number(e[2]))*1000
                ]
                val.curr = !val.curr
            }

            this.handleGetLis(0)
        },
        handleChangeTime(){ //自由设置的
            if(this.time){
                for(var tval of this.timeType){
                    tval.curr = false
                    if(today.otherTime(this.time[0], 'hh:mm') == tval.time.s.substring(0,5) && today.otherTime(this.time[1], 'hh:mm') == tval.time.e.substring(0,5)){
                        tval.curr = true
                    }
                }
                this.handleGetLis(0)
            }else {
                setTimeout(()=>{
                    this.handleSetTime(this.timeType[0],0);
                },10)
            }
        },
        getDayLis(data){
            this.dayLis = {
                data: [],
                types: []
            },
            this.dayLis.data = data.filter(v => v.step == 0)
            let arr = Array.from(new Set(data.map(v => v.namewc)))
            arr.forEach(v => {
                let obj = {
                    namewc: v,
                    totals: 0
                }
                obj.totals = this.dayLis.data.filter(v2 => v2.namewc == v).length
                this.dayLis.types.push(obj)
            })
        },
        //显示列表
        handleGetLis(opt, order){
            //获取医废信息  参数 科室，日期，时间
            this.currOrders = [];
            this.tableData  = [];
            this.exportDay = today.otherTime(this.day,'YY-MM-DD')
            let o = {
                sday: this.exportDay,//2015-05-05 开始时间
                eday: this.exportDay,//结束时间
                stime: today.otherTime(new Date(this.time[0]),'hh:mm'),//00:00 开始时刻
                etime: today.otherTime(new Date(this.time[1]),'hh:mm') //结束时刻
            }
            this.showDate = {
                day:this.exportDay,
                time: o.stime == '00:00' && o.etime == '23:59' ? '' : o.stime+'-'+o.etime,
                amtime: `${today.otherTime(new Date(this.customForm.time1[0]),'hh:mm')}-${today.otherTime(new Date(this.customForm.time1[1]),'hh:mm')}`,
                pmtime: `${today.otherTime(new Date(this.customForm.time2[0]),'hh:mm')}-${today.otherTime(new Date(this.customForm.time2[1]),'hh:mm')}`
            }
            console.log('showDate',this.showDate);
            jQuery.ajax({
                url:  diytimeUrl,
                type: 'GET',
                success: function(data){
                    if(data.success){
                        if(data.data.length != 0){
                            this.showDate.amtime = `${data.data[0].st}-${data.data[0].et}`
                            this.showDate.pmtime = `${data.data[1].st}-${data.data[1].et}`
                            this.customForm.time1 = [
                                new Date(`${this.exportDay} ${data.data[0].st}:59`),
                                new Date(`${this.exportDay} ${data.data[0].et}:00`)
                            ]
                            this.customForm.time2 = [
                                new Date(`${this.exportDay} ${data.data[1].st}:59`),
                                new Date(`${this.exportDay} ${data.data[1].et}:00`)
                            ]
                        }else{
                        }
                        jQuery.ajax({
                            url: getWasteCategoryUrl,
                            type: 'POST',
                            data: JSON.stringify(o),
                            success: function(res){
                                if(!res.success) {
                                    throwErrorTips('获取失败',res.msg)
                                    this.disabled = true;
                                    return
                                }

                                if(res.data.order.length > 0){
                                    this.currOrders = res.data.order.map(v => v.id)
                                    // 获取所有未签收的单
                                    this.getDayLis(res.data.order)
                                    if(o.stime == '00:00' && o.etime == '23:59'){
                                        this.handleGetAll(res, opt, order)
                                    }else{
                                        let lis1 = {title:'已交接',staff:[],time:'',typeL:[]},
                                            lis2 = {title:'点击交接',staff:[],time:'',typeL:[],ks:[],types:res.data.type},
                                            typeL = [],
                                            typeL2 = [],
                                            ks = [];
                                        for(var typeo of res.data.type){
                                            let o =  typeo;
                                            o['lis'] = [];
                                            o['weight'] = 0;
                                            o['num'] = 0;
                                            o = JSON.stringify(o)
                                            typeL.push(JSON.parse(o));
                                            typeL2.push(JSON.parse(o));
                                        }
                                        for(let k of res.data.ks){
                                            let o = {ks:k};
                                            o['lis'] = [];
                                            o['weight'] = 0;
                                            o['num'] = 0;
                                            ks.push(o);
                                        }
                                        for(var od of res.data.order){
                                            if(od.step != 0){
                                                lis1.staff.push(od.uname)
                                                for(let ty of typeL){
                                                    if(ty.title == od.namewc){
                                                        ty.lis.push(od);
                                                        ty.weight += Number(od.weight);
                                                        ty.num += Number(od.num)
                                                    }
                                                }

                                            }else {
                                                lis2.staff.push(od.uname);
                                                for(let ty of typeL2){
                                                    if(ty.title == od.namewc){
                                                        ty.lis.push(od);
                                                        ty.weight += Number(od.weight);
                                                        ty.num += Number(od.num)
                                                    }
                                                }
                                                //按科室
                                                let ind = res.data.ks.indexOf(od.place);
                                                if(ind != -1){
                                                    ks[ind].lis.push(od);
                                                    ks[ind].weight +=  Number(od.weight);
                                                    ks[ind].num += Number(od.num)
                                                }
                                            }
                                        }
                                        lis1.staff = Array.from(new Set(lis1.staff));
                                        lis2.staff = Array.from(new Set(lis2.staff));
                                        lis2.ks = ks;
                                        typeL.forEach((value,ind)=>{
                                            if(value.lis.length > 0){
                                                lis1.typeL.push(value)
                                            }
                                        })
                                        typeL2.forEach((value,ind)=>{
                                            if(value.lis.length > 0){
                                                lis2.typeL.push(value)
                                            }
                                        })
                                        if(lis1.typeL.length > 0){
                                            this.tableData.push(lis1)
                                        }
                                        if(lis2.typeL.length > 0){
                                            this.tableData.push(lis2)
                                            if(opt==1){
                                                this.handleShowConfirm(lis2)
                                            }
                                        }
                                    }
                                    this.getUndoLis()
                                    if(this.undoTableData.length == 0 && this.canShowDayLis){  // 判断当前是否有未交接数据，如没有，则直接弹窗，提示可以导出上次选的时间
                                        this.canShowDayLis = false;
                                        this.canShowTips = true;
                                    }
                                    
                                }
                                
                                this.disabled = false;
                            }.bind(this)
                        })
                    }
                }.bind(this)
            })
            this.getWasteNumber();
        },
        getUndoLis(data){
            this.undoTableData = []
            this.tableData.forEach(v => {
                if(v.title == '点击交接'){
                    this.undoTableData.push(Object.assign({}, v, {
                        date: this.exportDay
                    }))
                }
            })
            console.log('getUndoLis...');
            console.log(this.tableData);
            console.log(this.undoTableData);
        },
        handleGetAll(res, opt, order = null){
            let amlis1 = {title:'已交接',name:'已交接',time:this.showDate.amtime,staff:[],typeL:[]},
                pmlis1 = {title:'已交接',name:'已交接',time:this.showDate.pmtime,staff:[],typeL:[]},
                amlis2 = {title:'点击交接',name:'待交接',time:this.showDate.amtime,staff:[],typeL:[],ks:[],types:res.data.type},
                pmlis2 = {title:'点击交接',name:'待交接',time:this.showDate.pmtime,staff:[],typeL:[],ks:[],types:res.data.type},
                amlis3 = {title:'暂无数据',name:'未产生数据',time:this.showDate.amtime,staff:[],typeL:[]},
                pmlis3 = {title:'暂无数据',name:'未产生数据',time:this.showDate.pmtime,staff:[],typeL:[]},
                amtypeL = [], pmtypeL = [],
                amtypeL2 = [], pmtypeL2 = [],
                amtypeL3 = [], pmtypeL3 = [],
                amks = [], pmks = [];
            for(var typeo of res.data.type){
                let o =  typeo;
                o['lis'] = [];
                o['weight'] = 0;
                o['num'] = 0;
                o = JSON.stringify(o)
                amtypeL.push(JSON.parse(o));
                pmtypeL.push(JSON.parse(o));
                amtypeL2.push(JSON.parse(o))
                pmtypeL2.push(JSON.parse(o))
                amtypeL3.push(JSON.parse(o))
                pmtypeL3.push(JSON.parse(o))
            }
            for(let k of res.data.ks){
                let o = {ks:k};
                o['lis'] = [];
                o['weight'] = 0;
                o['num'] = 0;
                amks.push(o);
                pmks.push(o);
            }
            for(var od of res.data.order){
                if(od.step != 0){
                    if(od.ctime.split(' ')[1] <= this.showDate.amtime.split('-')[1]+':59'){
                        amlis1.staff.push(od.uname)
                        for(let ty of amtypeL){
                            if(ty.title == od.namewc){
                                ty.lis.push(od);
                                ty.weight += Number(od.weight);
                                ty.num += Number(od.num)
                            }
                        }
                    }else{
                        pmlis1.staff.push(od.uname)
                        for(let ty of pmtypeL){
                            if(ty.title == od.namewc){
                                ty.lis.push(od);
                                ty.weight += Number(od.weight);
                                ty.num += Number(od.num)
                            }
                        }
                    }
                }else {
                    if(od.ctime.split(' ')[1] >= this.showDate.amtime.split('-')[0] && od.ctime.split(' ')[1] <= this.showDate.amtime.split('-')[1]+':59'){
                        amlis2.staff.push(od.uname)
                        for(let ty of amtypeL2){
                            if(ty.title == od.namewc){
                                ty.lis.push(od);
                                ty.weight += Number(od.weight);
                                ty.num += Number(od.num)
                            }
                        }
                        let ind = res.data.ks.indexOf(od.place);
                        if(ind != -1){
                            amks[ind].lis.push(od);
                            amks[ind].weight +=  Number(od.weight);
                            amks[ind].num += Number(od.num)
                        }
                    }else if(od.ctime.split(' ')[1] >= this.showDate.pmtime.split('-')[0] && od.ctime.split(' ')[1] <= this.showDate.pmtime.split('-')[1]+':59'){
                        pmlis2.staff.push(od.uname)
                        for(let ty of pmtypeL2){
                            if(ty.title == od.namewc){
                                ty.lis.push(od);
                                ty.weight += Number(od.weight);
                                ty.num += Number(od.num)
                            }
                        }
                        let ind = res.data.ks.indexOf(od.place);
                        if(ind != -1){
                            pmks[ind].lis.push(od);
                            pmks[ind].weight +=  Number(od.weight);
                            pmks[ind].num += Number(od.num)
                        }
                    }
                }
            }
            amlis1.staff = Array.from(new Set(amlis1.staff));
            pmlis1.staff = Array.from(new Set(pmlis1.staff));
            amlis2.staff = Array.from(new Set(amlis2.staff));
            pmlis2.staff = Array.from(new Set(pmlis2.staff));
            amlis2.ks = amks;
            pmlis2.ks = pmks;
            amtypeL.forEach((value,ind)=>{
                if(value.lis.length > 0){
                    amlis1.typeL.push(value)
                }
            })
            pmtypeL.forEach((value,ind)=>{
                if(value.lis.length > 0){
                    pmlis1.typeL.push(value)
                }
            })
            amtypeL2.forEach((value,ind)=>{
                if(value.lis.length > 0){
                    amlis2.typeL.push(value)
                }
            })
            pmtypeL2.forEach((value,ind)=>{
                if(value.lis.length > 0){
                    pmlis2.typeL.push(value)
                }
            })
            amtypeL3.forEach((value,ind)=>{
                if(this.canHideEmptyType){
                    if(value.lis.length == 0){
                        amlis3.typeL.push(value)
                    }
                }else{
                    amlis3.typeL.push(value)
                }
            })
            pmtypeL3.forEach((value,ind)=>{
                if(this.canHideEmptyType){
                    if(value.lis.length == 0){
                        pmlis3.typeL.push(value)
                    }
                }else{
                    pmlis3.typeL.push(value)
                }
            })
            if(amlis1.typeL.length > 0){
                this.tableData.push(amlis1)
            }
            if(pmlis1.typeL.length > 0){
                this.tableData.push(pmlis1)
            }
            if(amlis2.typeL.length > 0){
                this.tableData.push(amlis2)
                if(order!=null && order.time == this.showDate.amtime){
                    this.confirmOrder = amlis2
                    this.confirmShow = true
                }
            }
            if(pmlis2.typeL.length > 0){
                this.tableData.push(pmlis2)
                if(order!=null && order.time == this.showDate.pmtime){
                    this.confirmOrder = pmlis2
                    this.confirmShow = true
                }
            }
            if(!this.canHideEmptyType){
                this.tableData.push(amlis3)
                this.tableData.push(pmlis3)
            }
            let amArr = [], pmArr = [];
            amlis2.typeL.forEach(v => amArr.push(v.title))
            pmlis2.typeL.forEach(v => pmArr.push(v.title))
            amlis3.typeL = amlis3.typeL.filter(v => amArr.indexOf(v.title) == -1)
            pmlis3.typeL = pmlis3.typeL.filter(v => pmArr.indexOf(v.title) == -1)
        },
        //点击显示同类型的单
        handleShowClassifyOrder(order){
            if(order.lis.length == 0) return;  // 数量为0时不可点击查看
            this.orderLis = order;
            this.orderShow = true
        },
        //点击待交接
        handleShowConfirm(val){ //显示确认
        console.log("handleShowConfirm",val);
            if(val.title == '已交接' || val.staff.length == 0) return;
            this.confirmOrder = val;
            this.confirmShow = true
        },
        handleSureSuccess(type,order){
            //二次确认成功后的操作
            this.confirmShow = false;
            if(type == 1){
                this.handleGetLis(0, order)
            }else {
                this.handleGetLis(1, order);
            }
        }
    },
    components: {
        WasteLis,
        HandConfirm,
        Calendar,
        ExportBtn,
        SignModal,
        ExportWarmTips,
        BatchHandover,
    }
	}
</script>
